function [fdata_x, fdata_y, Imax, a, v05, err, pcterr] = activation_fit(x_data, y_data, lam, params, maxiter)
% activation parameter fitting
% try single boltzmann fit  I=(V-Vr)Imax/(1+exp(-a*z*(V-V0.5));
% Fits directly to current, where Imax, z and V0.5 are the variables, and
% Vr and a are constants (beta and alpha, respectively)


model=21;	%single boltzman without normalization, and has an offset
alpha=(10^-3)*9.648*10^4/(8.3143*(273.16+params(2)));	%1/25mV  =F/RT
beta = params(1);
FitData(:,1)=x_data';
FitData(:,2)=y_data';

%parameters: imax     z       V0.5 
initpar = lam;
[m, k]=max(y_data);
m0 = m/(x_data(k)-beta);
initpar = [0 5 -50];
pmask =   [   1,       1,       1];
lbound =  [-m0,    0,   -150];
ubound =  [ 3*m0,     20,    50];
order=length(initpar);
maxiter=1000;


[c,lam]=curve_fitting(FitData(:,1), FitData(:,2), 'levenberg','cubic', model, order, initpar,...
   pmask, lbound, ubound, alpha, beta, maxiter);

%now plot it
t = FitData(:,1); 
z = FitData(:,2);
f = ((t-beta).*lam(1))./(1+exp(-lam(2)*alpha*(t-lam(3))));
err=sum((z-f).^2)
pcterr = sum(abs(z-f))*100;
fdata_x=min(x_data):2:max(x_data); %calculate more values, so the curve looks smooth
zy=zeros(1, length(fdata_x));
fdata_y=-fit_func(lam, fdata_x, zy, model, alpha, beta); 
%fdata_y=((fdata_x-beta).*lam(1))./(1+exp(-lam(2)*alpha*(fdata_x-lam(3))));
Imax=lam(1); a=lam(2); v05=lam(3);

